package addon.w3.mdx.com;

import java.io.IOException;

import addon.w3.mdx.MDXCOM;
import addon.w3.mdx.LEDataInputStream;
import addon.w3.mdx.MDXException;

/**
struct {
		long	nbytesi;
		float	staticAlpha;		(1.0:use KGAO)
		long	ColorAnimation;		(0:none;1:DropShadow;2:Color;3:Both)
		float	ColorR, ColorG, ColorB; (default:1)
		long	GeosetID;
		(KGAO)
		(KGAC)
	} geosanims[ngsan];
 * @author madjk
 *
 */
public class MDXGeosetAnimCOM extends MDXCOM {
	int length = -1;
	float staticAlpha;
	int colorAnimation = -1;
	float colR,colG,colB;
	int geosetID = -1;
	
	MDXAlpha kgao = null;
	MDXScaling kgac = null;
	
	public String getTag() {
		return "GEOA:animation";
	}
	
	public void _decode(LEDataInputStream ins) throws IOException, MDXException {
		length = ins.readInt();
		staticAlpha = ins.readFloat();
		colorAnimation = ins.readInt();
		colR = ins.readFloat();
		colG = ins.readFloat();
		colB = ins.readFloat();
		geosetID = ins.readInt();
		
		byte temp[] = new byte[4];
		ins.read(temp);
		String tag = new String(temp);
		if(tag.equals("KGAO")) {
			kgao = new MDXAlpha("KGAO","KGAO:Alpha");
			kgao.decode(ins);
		} else if(tag.equals("KGAC")) {
			kgac = new MDXScaling("KGAC","KGAC:Color");
			kgac.decode(ins);
			return;
		} else {
			ins.unread(temp);
			return;
		}
		
		temp = new byte[4];
		ins.read(temp);
		tag = new String(temp);
		if(tag.equals("KGAC")) {
			kgac = new MDXScaling("KGAC","KGAC:Color");
		} else {
			ins.unread(temp);
			return;
		}
		//debug( this.toString() );
	}
	
	public String toString() {
		StringBuffer sb = new StringBuffer();
		sb.append("TAG : "+getTag());
		sb.append("\n\tILEN : "+length);
		sb.append("\n\tSTATICALPHA : "+staticAlpha);
		sb.append("\n\tCOLORANIMATION : "+colorAnimation);
		sb.append("\n\tCOLOR_RGB : "+colR+" : "+colG+" :"+colB);
		sb.append("\n\tGEOSETID : "+geosetID);
		sb.append("\n\tKGAO : "+(kgao == null ? false : kgao.toString()));
		sb.append("\n\tKGAC : "+(kgac == null ? false : true));
		return sb.toString();
	}

	@Override
	public boolean isImplicitTag() {
		// TODO Auto-generated method stub
		return false;
	}
}
